package com.shop.common.advice;

import com.shop.common.enums.ExceptionEnum;
import com.shop.common.exception.ShopException;
import com.shop.common.vo.ExceptionResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author : Created by HGL on 2019/03/23 13:15
 * @version : 1.0
 * Description :
 */
@ControllerAdvice
public class CommonExceptionHandler {

    @ExceptionHandler(ShopException.class)
    public ResponseEntity<ExceptionResult> handleException(ShopException e) {
        ExceptionEnum em = e.getExceptionEnum();
        return ResponseEntity.status(em.getCode()).body(new ExceptionResult(e.getExceptionEnum()));
    }
}
